﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Member_OrderCancel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetCancelReasonList();
        }
    }

    private void SetCancelReasonList()
    {
        ArrayList al = new ArrayList();
        al.Add("商品价格过高");
        al.Add("需要更换产品");
        al.Add("订单未按承诺时间发货");
        al.Add("需要修改发票信息");
        al.Add("需要修改配送方式");
        al.Add("支付不成功");
        al.Add("需要修改支付方式");
        al.Add("需要添加商品");
        al.Add("需要删除商品");
        al.Add("预计发货时间太长");
        al.Add("暂时不需要");
        al.Add("需要修改配送地址");
        al.Add("配送费过高");
        al.Add("下了同样的订单");
        dlCancelReason.DataSource = al;
        dlCancelReason.DataBind();
    }
    protected void btnOrderCancel_Click(object sender, EventArgs e)
    {
        GoShopping.Model.CancledOrders co = new GoShopping.Model.CancledOrders();
        co.CancleDate = DateTime.Now;
        if (Request.QueryString["orderId"] != null)
        {
            co.OrderID = Convert.ToInt32(Request.QueryString["orderId"]);
        }
        IEnumerator ienum=dlCancelReason.Items.GetEnumerator();
        while (ienum.MoveNext())
        {
            if (((RadioButton)(((DataListItem)ienum.Current).FindControl("rbSendWay"))).Checked)
            {
                co.Reason = ((RadioButton)(((DataListItem)ienum.Current).FindControl("rbSendWay"))).Text;
            }
        }
        foreach (DataListItem dli in dlCancelReason.Items)
        {
            if (((RadioButton)dli.FindControl("rbSendWay")).Checked)
            {
                co.Reason = ((RadioButton)dli.FindControl("rbSendWay")).Text;
            }
        }
        GoShopping.BLL.Orders.OrderBean ob = new GoShopping.BLL.Orders.OrderBean();
        try
        {
            ob.CancleOrderRecord(co);
            ob.UpdateOrder(co.OrderID, GoShopping.Model.Enumerations.OrderStatusType.Canceled);
            Response.Redirect("MyOrder.aspx");
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.Message);
        }
    }
}
